using System;
using System.Globalization;
using Avalonia.Data.Converters;

namespace torch.ui.Converters;

public sealed class TextIsNullToOpacityConverter : IValueConverter
{
    public static TextIsNullToOpacityConverter Instance { get; } = new();

    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string text && !string.IsNullOrWhiteSpace(text))
        {
            return 1d;
        }

        return 0d;
    }

    public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
        throw new NotSupportedException();
}

public sealed class BooleanToFavoriteIconConverter : IValueConverter
{
    public static BooleanToFavoriteIconConverter Instance { get; } = new();

    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        var isFavorite = value is true;
        return isFavorite ? "\uf004" : "\uf08a";
    }

    public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
        throw new NotSupportedException();
}
